package com.rc.saas.tenant.service.elec;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rc.saas.tenant.mapper.elec.ElecStationPriceMapper;
import com.rc.saas.tenant.model.elec.ElecStationPrice;
import com.rc.saas.tenant.model.elec.ElecStationPriceExample;
import com.rc.saas.tenant.search.elec.ElecStationPriceSearch;
import com.rc.saas.tenant.vo.hlht.HlhtTenantOpenStationPriceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author frog
 * @date 2019/11/11
 */
@Service
public class ElecStationPriceServiceImpl implements ElecStationPriceService {

    @Autowired
    private ElecStationPriceMapper elecStationPriceMapper;

    @Override
    public ElecStationPriceMapper getMapper() {
        return elecStationPriceMapper;
    }

    @Override
    public PageInfo<ElecStationPrice> searchByCondition(ElecStationPriceSearch elecStationPriceSearchVo) {
        PageHelper.startPage(elecStationPriceSearchVo.getOffset(), elecStationPriceSearchVo.getLimit());
//        ElecStationPriceExample example = new ElecStationPriceExample();
//        example.createCriteria().andElecStationIdEqualTo(elecStationPriceSearchVo.getElecStationId())
//                .andTenantCodeEqualTo(elecStationPriceSearchVo.getTenantCode());
//        List<ElecStationPrice> elecStationPrices = elecStationPriceMapper.selectByExample(example);
        List<ElecStationPrice> elecStationPrices = elecStationPriceMapper.listByElecStationId(elecStationPriceSearchVo.getElecStationId());
        return new PageInfo<ElecStationPrice>(elecStationPrices);
    }

    @Override
    public List<ElecStationPrice> listPriceByStationId(Long elecStationId) {
        ElecStationPriceExample example = new ElecStationPriceExample();
        example.createCriteria().andElecStationIdEqualTo(elecStationId);
        List<ElecStationPrice> stationPriceList = elecStationPriceMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(stationPriceList)){
            return stationPriceList;
        }
        return null;
    }

    @Override
    public List<HlhtTenantOpenStationPriceVo> listStationPriceAndOpenPrice(String tenantCode,String hlhtOpenType,
                                                                           String hlhtTenantCode,String hlhtOperatorId,
                                                                           Long elecStationId) {
        return elecStationPriceMapper.listStationPriceAndOpenPrice(tenantCode,hlhtOpenType,hlhtTenantCode,hlhtOperatorId,elecStationId);
    }

    @Override
    public void insertSelectiveReturnId(ElecStationPrice elecStationPrice) {
        elecStationPriceMapper.insertSelectiveReturnId(elecStationPrice);
    }
}
